<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\adminapi\controller\goods;

use app\adminapi\controller\Base;
use app\service\goods\TextContentService;

class Chapter extends Base
{
    /**
     * Add chapter group
     */
    public function addGroup()
    {
        $data = [
            'goods_id' => inputs("goods_id/d", 0),
            'title'    => inputs("title/s", ""),
            'sort'     => inputs("sort/d", 0),
        ];

        if (empty($data['goods_id'])) {
            $this->error(trans('goods_id_required'));
        }

        if (empty($data['title'])) {
            $this->error(trans('group_title_required'));
        }

        $service = new TextContentService();
        $group   = $service->addGroup($data);

        $this->success('', $group);

    }

    /**
     * Edit chapter group
     * Groups don't need to set charge type
     */
    public function editGroup()
    {
        $id   = inputs("id/d", 0);
        $data = [
            'title' => inputs("title/s", ""),
            'sort'  => inputs("sort/d", null),
        ];

        if (empty($id)) {
            $this->error(trans('group_id_required'));
        }


        $service = new TextContentService();
        $group   = $service->editGroup($id, $data);

        $this->success('', $group);

    }

    /**
     * Delete chapter group
     */
    public function delGroup()
    {
        $id = inputs("id/d", 0);

        if (empty($id)) {
            $this->error(trans('group_id_required'));
        }


        $service = new TextContentService();
        $service->deleteGroup($id);

        $this->success();

    }
}
